﻿----------------------------------------------------------------------------------------------------
--
--  © 2012 Stanislav S. Yarmonov.
--
--  TODO:LICENSE
--     
----------------------------------------------------------------------------------------------------
IF OBJECT_ID(N'[_DB].[Function_Exists]', N'P') IS NOT NULL
	DROP PROCEDURE [_DB].[Function_Exists]
GO

----------------------------------------------------------------------------------------------------
--
--  Check the existance of the user-defined function.
--
--  INPUT
--		@@Name
--		Name of the user-defined function to be checked.
--
----------------------------------------------------------------------------------------------------
CREATE FUNCTION [_DB].[Function_Exists] (
	@@Name [sysname]
)
RETURNS [bit]
AS
BEGIN
	RETURN CASE
		WHEN OBJECT_ID(@@Name, 'FN') IS NOT NULL THEN 1
		WHEN OBJECT_ID(@@Name, 'TF') IS NOT NULL THEN 1
		WHEN OBJECT_ID(@@Name, 'IF') IS NOT NULL THEN 1
		WHEN OBJECT_ID(@@Name, 'AF') IS NOT NULL THEN 1
		WHEN OBJECT_ID(@@Name, 'FS') IS NOT NULL THEN 1
		WHEN OBJECT_ID(@@Name, 'FT') IS NOT NULL THEN 1
		ELSE 0
	END
END
GO
